package com.zhaokuner.parentstarter.common;

import com.zhaokuner.parentstarter.resultcode.ResultCode;
import com.zhaokuner.parentstarter.resultcode.SuperResultCodeUtil;
import lombok.ToString;

/**
 * 类描述:即返回 状态 有返回数据
 *
 * @author 赵希坤 zhaoxikun
 * @date 2020/12/21 19:19
 */
@ToString
public class ResultBean<T> {
    /**
     * 状态
     */
    public ResultCode resultCode;
    /**
     * 数据
     */
    public T bean;

    public Exception e;

    public ResultBean() {

    }


    public ResultBean(ResultCode resultCode, T bean) {
        this.resultCode = resultCode;
        this.bean = bean;
    }

    public static <T> ResultBean<T> resultCode(ResultCode resultCode) {
        return new ResultBean<>(resultCode, null);
    }

    public static <T> ResultBean<T> error() {
        return new ResultBean<>(SuperResultCodeUtil.FAILURE, null);
    }

    public static <T> ResultBean<T> error(T bean) {
        return new ResultBean<>(SuperResultCodeUtil.FAILURE, bean);
    }

    public static <T> ResultBean<T> success() {
        return new ResultBean<>(SuperResultCodeUtil.SUCCESS, null);
    }

    public static <T> ResultBean<T> success(T bean) {
        return new ResultBean<>(SuperResultCodeUtil.SUCCESS, bean);
    }


    public ResultBean<T> bean(T bean) {
        this.setBean(bean);
        return this;
    }

    public ResultBean<T> e(Exception e) {
        this.setE(e);
        return this;
    }

    public ResultCode getResultCode() {
        return resultCode;
    }

    public void setResultCode(ResultCode resultCode) {
        this.resultCode = resultCode;
    }

    public T getBean() {
        return bean;
    }

    public void setBean(T bean) {
        this.bean = bean;
    }

    public Exception getE() {
        return e;
    }

    public void setE(Exception e) {
        this.e = e;
    }

}
